QTimer::remainingTime()在win7和CentOS6.5上的差异 您所在的位置:网站首页 remaining time QTimer::remainingTime()在win7和CentOS6.5上的差异

QTimer::remainingTime()在win7和CentOS6.5上的差异

#QTimer::remainingTime()在win7和CentOS6.5上的差异| 来源: 网络整理| 查看: 265

环境 CentOS

about QT: Qt Creator 2.8.1 , Based on Qt 5.1.1 (GCC 4.6.1, 32 bit) 编译器:GCC 4.9.1 系统:Linux CentOS.com 2.6.32-642.15.1.el6.i686 #1 SMP Fri Feb 24 13:54:50 UTC 2017 i686 i686 i386 GNU/Linux kit: Desktop Qt 5.1.1 GCC 32 bit

windows

about QT: Qt Creator 4.2.1,Based on Qt 5.8.0 (MSVC 2015, 32 bit) 编译器:MinGW 4.8 32 bit MinGW 系统:windows 7 旗舰版 64 bits kit: Desktop Qt 5.1.1 MinGW 32 bit

程序概述

每隔3秒钟,textEdit上的数字加1(最初是0),每隔1秒钟,label上的更新当前的距离timeout触发事件的剩余时间,格式为时:分:秒。

表现 centos

在CentOS上程序运行和预想的是一样的。3秒钟一次在textEdit上产生不断变大的数字,在label中显示距离下一次事件发生还剩下多少时间。

这里写图片描述

win7

在win7上,myTimer::remainingTime()返回结果在第一次变成0后以后一直都是0. 但myTimer是正常让TextEdit的数字每三秒一次的更新,不过myTimer::remainingTime()的返回值在第一次由3变0后就不再变化一直是0了,好像在说,“嘿,哥们儿,你的Timer过期了。” 这里写图片描述

具体代码

mTimer.pro:

#------------------------------------------------- # # Project created by QtCreator 2017-03-08T18:30:37 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = mTimer TEMPLATE = app SOURCES += main.cpp\ dialog.cpp HEADERS += dialog.h FORMS += dialog.ui

dialog.h

#ifndef DIALOG_H #define DIALOG_H #include #include namespace Ui { class Dialog; } class Dialog : public QDialog { Q_OBJECT protected: qint8 count; QTimer *myTimer; QTimer *showTimer; public: explicit Dialog(QWidget *parent = 0); ~Dialog(); public slots: void update(); void showTime(); private: Ui::Dialog *ui; }; #endif // DIALOG_H

dialog.cpp

#include "dialog.h" #include "ui_dialog.h" #include Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); count = 0; myTimer = new QTimer(this); showTimer = new QTimer(this); showTimer->start(1 * 1000); myTimer->start(3 * 1000 ); myTimer->setSingleShot(false); connect(myTimer,SIGNAL(timeout()),this,SLOT(update())); connect(showTimer,SIGNAL(timeout()),this,SLOT(showTime())); } Dialog::~Dialog() { delete ui; } void Dialog::update() { count++; ui->textEdit->setText(QString::number(count)); } void Dialog::showTime() { int mesc = myTimer->remainingTime(); int hour = mesc/1000/60/60; int minute = mesc/1000/60 - hour*60; int sec = mesc/1000-hour*60*60-minute*60; QString str; str = str + QString::number(hour)+":"; str = str + QString::number(minute)+":"; str = str + QString::number(sec); ui->leftLabel->setText(str); QFont font("Microsoft YaHei",20); ui->leftLabel->setFont(font); }

main.cpp

#include "dialog.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); Dialog w; w.show(); return a.exec(); } 版本更新,恢复正常

17.03.24更新: 我安装最新离线版本的qt后,win7上的怪现象消失了,时间是由3秒变成0秒,然后不断重复这个过程。还是同样的代码,kit也是一样,不过kit和编译器的版本更新了。 about QT: Qt Creator 4.2.1; Based on Qt 5.8.0 (MSVC 2015, 32 bit) 编译器:5.8.0 32 bit MinGW 系统:windows 7 旗舰版 64 bits kit: Desktop Qt 5.8.0 MinGW 32 bit

这里写图片描述



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有